import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
// 引入全部组件及样式
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import {resetForm,addDateRange,selectDictLabel,selectDictLabels} from '@/utils/ds.js'
import modal from './plugins/modal.js'
//引入mock模拟后端数据
// import "@/mockjs/index";
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)

app.config.globalProperties.$resetForm = resetForm;
app.config.globalProperties.$addDateRange = addDateRange;
app.config.globalProperties.$selectDictLabel = selectDictLabel;
app.config.globalProperties.$selectDictLabels = selectDictLabels;
app.config.globalProperties.$modal = modal

app.config.productionTip = false

// 全局注册，之后可在其他组件中通过 this.$axios 发送数据
app.config.globalProperties.$axios = axios
// 设置反向代理
// axios.defaults.baseURL =  'http://5u99xa.natappfree.cc'; 
axios.defaults.baseURL =  'http://localhost:8081'; 
// axios.defaults.baseURL =  'http://192.168.43.168:8081';
//钩子函数，访问路由前调用
router.beforeEach((to, from, next) => {
    //路由需要认证
    if (to.meta.requireAuth) {
      //判断store里是否有token
      if (store.state.token) {
        next()
      } else {
        next({
          path: 'login',
          query: { redirect: to.fullPath }
        })
      }
    } else {
      next()
    }
  }
  )

//  统一注册el-icon图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.use(store)
app.use(router)
// app.use(plugins)

// 注册全部组件
app.use(ElementPlus)

app.mount('#app')
